<template>
	<!-- 员工详情 -->
  <div class="stu">
	 <el-dialog v-loading="loading"  :title="num==1?'编辑医保未登记信息':'新增医保未登记信息'" :visible.sync="dialogVisible" width="35%" :before-close="handleClose"  :close-on-click-modal='false'>
	   <!-- <p class="pbox" style="text-align: center;width:100%;font-size:30px;height:40px;">员工信息详情</p> -->
	    <div style="width:100%;padding-bottom:20px;">
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>选择地区</p>
					<el-select :disabled='num==1' style='width:37%;' @change='activess.group_name="";' v-model="activess.village_name" clearable filterable placeholder="选择行政村">
					  <el-option v-for='i in $store.state.cunid' :label="i.label" :value="i.label"></el-option>
					</el-select>
					<el-select :disabled='num==1' style='width:37%;' v-model="activess.group_name" clearable filterable placeholder="选择村组">
					  <el-option v-for='i in activeput(gitcode(activess.village_name,$store.state.cunid),$store.state.cunzuid)' :label="i.label" :value="i.label"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>姓名</p>
					<el-input style='width:75%;'  placeholder="请输入" v-model="activess.name" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>性别</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.sex" clearable filterable placeholder="请选择">
					  <el-option :label="'男'" :value="'1'"></el-option>
					  <el-option :label="'女'" :value="'0'"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>出生年月</p>
					<el-input style='width:75%;' :disabled='num==1' placeholder="请输入" v-model="activess.birth_year_month" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>身份证号</p>
					<el-input style='width:75%;' :disabled='num==1' placeholder="请输入" v-model="activess.card" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>地址</p>
					<el-input style='width:75%;'  placeholder="请输入" v-model="activess.address" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>发放标准</p>
					<el-input style='width:75%;'  placeholder="请输入" type='number' min='0' v-model="activess.grant_stand" clearable>
						<el-button  slot="append" >￥</el-button>
					</el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>发放金额</p>
					<el-input style='width:75%;'  placeholder="请输入" type='number' min='0' v-model="activess.grant_money" clearable>
						<el-button  slot="append" >￥</el-button>
					</el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>银行卡号</p>
					<el-input style='width:75%;'  placeholder="请输入" v-model="activess.bank_number" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>状态</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.status" clearable filterable placeholder="请选择">
					  <el-option :label="'未办理'" :value="'0'"></el-option>
					  <el-option :label="'已办理'" :value="'1'"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;height:100px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;"> </a>备注</p>
					<el-input style='width:75%;' type="textarea" :rows="5" class='tabinp' v-model="activess.comment" placeholder="请输入" clearable></el-input>
			</div>
			
		</div>	
		<div style="width:100%;height:40px;margin-top:20px;">
	      <div style="width:170px;margin: 0 auto;">
	        <el-button type="danger" @click="handleClose">取 消</el-button>
	        <el-button type="primary" style='float:right;' @click="git_acts">确 定</el-button>
	      </div>
		</div>
	 </el-dialog>
	
  </div>
</template>

<script>
import $ from 'jquery'
export default {
  name: 'stu',
  components: {},//声明子组件
  computed:{
	  docsa(){
	  		return function(i){
	  			for(let j=0;j<this.$store.state.suju_box.length;j++){
	  				if(this.$store.state.suju_box[j].value==i){
	  					return this.$store.state.suju_box[j].label;
	  				}
	  			}
	  		}  
	  },
	  activeput(){//联动判断，code 为上一级的code  act为当前未赛选的数据字典
	  	return function(code,act){
	  		let a = [];
	  		for(let i=0;i<act.length;i++){
	  			if(act[i].own_code==code){
	  				a.push(act[i]);
	  			}
	  		}
	  		return a;
	  	}
	  },
	  gitcode(){//通过id获取code
	  	return function(id,act){
	  		for(let i=0;i<act.length;i++){
	  			if(id==act[i].label){
	  				return act[i].code;
	  			    break
	  			}
	  		}
	  	}
	  },
	  rens(){//通过id查询当前这一项
		  return (data,id)=>{
			  for(let i=0;i<data.length;i++){
				  if(data[i].id==id){
					  return data[i]
				  }
			  }
		  }
	  },
	  fm(){//通过family_id查询当前这一项
	  		  return (data,id)=>{
	  			  for(let i=0;i<data.length;i++){
	  				  if(data[i].family_id==id){
	  					  return data[i]
	  				  }
	  			  }
	  		  }
	  },
  },
  data(){
	  return {
		loading:false,
		btn_shou:false,
		dialogVisible: false,
		activess:{
			          id:'',//主键
			          pop_id:'',//人口ID
			          name:'',//老人姓名
			          sex:'',//性别  1男 0 女
			          birth_year_month:'',//出生年月 如:2020-03 //不可编辑
			          address:'',//地址
			          village_name:'',//行政村名 // 不可编辑
			          group_name:'',//村小组名  // 不可编辑
			          card:'',//身份证号码  // 不可编辑
			          grant_stand:'',//发放标准
			          grant_money:'',//方法金额
			          bank_number:'',//银行卡号
			          comment:'',//备注  // 不要随便去填写死亡二字
			          status:'',//状态 (0未办理  1已办理)
		},
		jt:[],
		ry:[],
		renbox:[],
		num:0,
	  }
  },
  methods:{
	  qins(){
		  this.activess.name = '';
		  this.activess.card = '';
		  this.activess.age = '';
		  // this.activess.p_number = '';
		  // this.activess.pop_name = '';
		  // this.activess.card = '';
		  // this.activess.house_relation = '';
		  // this.activess.nation_id = '';
		  // this.activess.edu_id = '';
		  // this.activess.politic_id = '';
		  // this.activess.pover_id = '';
		  // this.activess.health_id = '';
	  },
	  renclick(i){//当用户选择了人员
	      this.qins();
	  	  let box = this.rens(this.ry,i);
		  console.log(box);
		  this.activess.name = box.name;
		  this.activess.card = box.card;
		  // this.activess.age = box.age;
		  // this.activess.p_number = box.p_number;
		  // this.activess.house_relation = box.house_relation;
		  // this.activess.nation_id = box.nation_id;
		  // this.activess.edu_id = box.edu_id;
		  // this.activess.politic_id = box.politic_id;
		  // this.activess.pover_id = box.pover_id;
		  // this.activess.health_id = box.health_id;
	  },
	  fam(i){
		 // this.ry=[];this.activess.h_number ='';
		 // this.activess.pop_id="";
		 // this.git_ren();
		 // this.qins()
		 let box = this.fm(this.jt,i);
		 this.activess.status = box.status;
		 console.log(this.fm(this.jt,i))
	  },
	  git_jia(i){//获取家庭信息
		  $.ajax({url:'/dj/user_pc/get_family_list',type:'post',
		      data:{
		  	     village_name:this.activess.village_name,
		  	     group_name:this.activess.group_name
		      },
		  	dataType:'json',success:(res)=>{
		  	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
		  	 if(res.code==200){
		  		 this.jt = res.data;
				 if(i){this.git_ren();}
		  		 console.log(this.jt,'家庭数据');
		  	 }
		  }})
	  },
	  git_ren(){//获取人口信息
	  	 $.ajax({url:'/dj/user_pc/get_family_detail',type:'post',
	  	     data:{
	  	 	     family_id:this.activess.family_id,
	  	     },
	  	 	dataType:'json',success:(res)=>{
	  	 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  	 	 if(res.code==200){
	  	 		 this.ry = res.data;
	  	 		 console.log(this.ry,'人口数据');
	  	 	 }
	  	 }})
	  },
	 
	  git_act(i,num){//获取数据的同打开狂口
	      if(num==1){
			  this.activess = i;
			  console.log(this.activess);
			  // this.activess.poor_rid_id = Number(this.activess.poor_rid_id);
			  this.activess.status = this.activess.status+'';
			  this.activess.sex = this.activess.sex+'';
			  // this.git_jia(true);
		  }
		  this.num = num;
	      // console.log(this.activess,num);
	      this.dialogVisible=true;
	  },
	  git_acts(){//提交数据
	        console.log(this.activess)
	        // if(this.isNull(this.activess.village_name)){this.$message.error('请选择 行政村');return false}
	        // if(this.isNull(this.activess.group_name)){this.$message.error('请选择 村组');return false}
			
			if(this.isNull(this.activess.name)){this.$message.error('请输入 老人姓名');return false}
			if(this.isNull(this.activess.sex)){this.$message.error('请选择 性别');return false}
			if(this.isNull(this.activess.address)){this.$message.error('请输入 地址');return false}
			if(this.isNull(this.activess.grant_stand)&&this.activess.grant_stand!=0){this.$message.error('请输入 发放标准');return false}
			if(this.activess.grant_stand<0){this.$message.error('发放标准不能小于零');return false}
			if(this.isNull(this.activess.grant_money)&&this.activess.grant_money!=0){this.$message.error('请输入 发放金额');return false}
			if(this.activess.grant_money<0){this.$message.error('发放金额不能小于零');return false}
			if(this.isNull(this.activess.bank_number)){this.$message.error('请输入 银行卡号');return false}
			if(this.isNull(this.activess.status)){this.$message.error('请选择 状态');return false}
			// if(this.isNull(this.activess.comment)){this.$message.error('请输入 备注');return false}
			// if(this.isNull(this.activess.card)){this.$message.error('请输入 身份证号');return false}
			// if(this.isNull(this.activess.age)){this.$message.error('请输入 年龄');return false}
			// if(this.activess.age>0){}else{this.$message.error('年龄 不能小于或等于零');return false}
			// if(this.iscard(this.activess.card)){this.$message.error('身份证号格式不正确');return false}
			// if(this.isNull(this.activess.is_cb)){this.$message.error('请选择 是否参保');return false}
			// if(this.isNull(this.activess.reason)){this.$message.error('请输入 未参保原因 ');return false}
	  		 let url = this.num==1?'/dj/convent_service/old_process_modify':'';
	  		 $.ajax({url:url,type:'post',data:this.activess,dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'提交');
	  		 	 if(res.code==200){
	  				this.$parent.git_act();
	  		 		this.$message({message: '操作成功',type: 'success'});
	  		 		this.dialogVisible=false;
	  				this.qin();
	  		 	  }else{
	  		 		 this.$message.error(res.msg);
	  		 	  }
	  		 	}
	  		 })
	  },
	  qin(){//清除
	  	this.activess={
			          id:'',//主键
			          pop_id:'',//人口ID
			          name:'',//老人姓名
			          sex:'',//性别  1男 0 女
			          birth_year_month:'',//出生年月 如:2020-03 //不可编辑
			          address:'',//地址
			          village_name:'',//行政村名 // 不可编辑
			          group_name:'',//村小组名  // 不可编辑
			          card:'',//身份证号码  // 不可编辑
			          grant_stand:'',//发放标准
			          grant_money:'',//方法金额
			          bank_number:'',//银行卡号
			          comment:'',//备注  // 不要随便去填写死亡二字
			          status:'',//状态 (0未办理  1已办理)
		}
	  },
	  
	  handleClose(done){//监测用户点击x
	     this.$confirm('确定取消关闭吗？','提示',{confirmButtonText:'确定',cancelButtonText:'取消',type: 'warning'
	     }).then(() => {
	  	   this.dialogVisible = false;
	  	   this.qin();
		   this.$parent.git_act();
	  	}).catch(() => {});
	  },
	  
  },
  mounted(){
	  // this.git_ren()
  }
}
</script>
<style scoped="scoped">
	
	.pboxc1{
		float:left;
		width:70%;
		height:40px;
		border:1px solid rgba(242,242,242,1);
		font-size:14px;color:#666666;
		/* padding-left:18px; */
		text-align:left;
		/* overflow: hidden; */
		/* text-overflow:ellipsis; */
		/* white-space: nowrap; */
	}
	.tabbox{
		width:100%;
		height:40px;
		line-height: 30px;
		margin-top:23px;
	}
	.tabbox p{
		font-size:14px;
		color:#000000;
		width:19.5%;
		text-align:right;
		margin-right:28px;
		float:left;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
	}
	.pbox{
		width:10%;
		text-align:right;
		height:26px;
		margin-bottom:20px;
		font-size:18px;
		color:#000101;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
		font-weight:600;
	}
</style>
